package com.zty.xiaomi.server.Controller;

import com.zty.xiaomi.server.Dto.AddEvidenceDto;
import com.zty.xiaomi.server.Dto.GetEvidenceInfoDto;

import com.zty.xiaomi.server.Entity.Evidence.Evidence;
import com.zty.xiaomi.server.Service.Evidence.EvidenceServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("evidence")
public class EvidenceController {

    @Autowired
    private EvidenceServiceImp evidenceServiceImp;

    @GetMapping("getEvidenceByTribunalId")
    private GetEvidenceInfoDto getEvidenceByTribunalId(@RequestParam("tribunal_id") int tribunal_id) throws IOException {
        GetEvidenceInfoDto getEvidenceInfoDto = new GetEvidenceInfoDto();
        List<Evidence> list = evidenceServiceImp.getEvidenceByTribunalId(tribunal_id);
        if (list.size() == 0) {
            getEvidenceInfoDto.setStatus("400");
            getEvidenceInfoDto.setMsg("双方暂无证据提交");
        } else {
            getEvidenceInfoDto.setStatus("200");
            getEvidenceInfoDto.setList(list);
        }
        return getEvidenceInfoDto;
    }

    @PostMapping("addEvidenceByTribunalId")
    private AddEvidenceDto addEvidenceByTribunalId(@RequestBody Evidence evidence) throws IOException {
        AddEvidenceDto addEvidenceDto = new AddEvidenceDto();
        int num = evidenceServiceImp.addEvidenceByTribunalId(evidence);
        if (num == 1) {
            addEvidenceDto.setStatus("200");
            addEvidenceDto.setMsg("提交成功");
        } else {
            addEvidenceDto.setStatus("400");
            addEvidenceDto.setMsg("提交失败");
        }
        return addEvidenceDto;
    }
}
